// *************************************************************************************************
//
// MK3D Engine
// --------------------------------------
// Copyright (C) 2007-2011 Zeb (mailto: zebbey@gmail.com)
//
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
//
// *************************************************************************************************

#include "mk_header.h"
#include "mk_texture_mapping.h"
#include "mk_error.h"

namespace MK3DE
{
	BOOL CTextureMapping::SetMapTextureData(DWORD matId, CTextureMapping::TextureData data)
	{
		MK_PROCESS_ERROR(matId < (DWORD)_vecMap.size());

		_vecMap[matId].textureData = data;
		return TRUE;

Exit0:
		return FALSE;
	}

	BOOL CTextureMapping::GetMapTextureData(DWORD matId, CTextureMapping::TextureData& data)
	{
		MK_PROCESS_ERROR(matId < (DWORD)_vecMap.size());

		data = _vecMap[matId].textureData;
		return TRUE;

Exit0:
		return FALSE;
	}

	BOOL CTextureMapping::GetMapTextureFile(DWORD matId, std::string& fileName)
	{   
		MK_PROCESS_ERROR(matId < (DWORD)_vecMap.size());

		fileName = _vecMap[matId].fileName;
		return TRUE;
Exit0:
		return FALSE;
	}

	BOOL CTextureMapping::GetMapTextureName(DWORD matId, std::string& name)
	{
		MK_PROCESS_ERROR(matId < (DWORD)_vecMap.size());

		name = _vecMap[matId].textureName;
		return TRUE;
Exit0:
		return FALSE;
	}

	BOOL CTextureMapping::GetMapTextureDataByName(const char* name, CTextureMapping::TextureData& data)
	{
		std::vector<CTextureMapping::Map>::iterator i = _vecMap.begin();
		while (i != _vecMap.end())
		{
			CTextureMapping::Map& map = *i;
			if (map.textureName == name)
			{
				data = map.textureData;
				return TRUE;
			}

			++i;
		}

		return FALSE;
	}

	BOOL CTextureMapping::GetMapTextureFileByName(const char* name, std::string& texFileName)
	{
		std::vector<CTextureMapping::Map>::iterator i = _vecMap.begin();
		while (i != _vecMap.end())
		{
			CTextureMapping::Map& map = *i;
			if (map.textureName == name)
			{
				texFileName = map.fileName;
				return TRUE;
			}

			++i;
		}

		return FALSE;
	}

	BOOL CTextureMapping::GetMapTextureNameByName(const char* name, std::string& texName)
	{
		std::vector<CTextureMapping::Map>::iterator i = _vecMap.begin();
		while (i != _vecMap.end())
		{
			CTextureMapping::Map& map = *i;
			if (map.textureName == name)
			{
				texName = map.textureName;
				return TRUE;
			}

			++i;
		}

		return FALSE;
	}

	BOOL CTextureMapping::RemoveMap(DWORD matId)
	{
		MK_PROCESS_ERROR(matId < (DWORD)_vecMap.size());

		_vecMap.erase(_vecMap.begin() + matId);

		return TRUE;
Exit0:
		return FALSE;
	}

	BOOL CTextureMapping::RemoveMapByName(const char* name)
	{
		std::vector<CTextureMapping::Map>::iterator i = _vecMap.begin();
		while (i != _vecMap.end())
		{
			CTextureMapping::Map& map = *i;
			if (map.textureName == name)
			{
				_vecMap.erase(i);
				return TRUE;
			}

			++i;
		}

		return FALSE;
	}
}